﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Windows.Forms;

namespace Controls.Message
{
    [ToolboxItem(false)]
    public partial class InfoIcon : Control
    {
        private Color _borderColor;
        private float _borderThickNess;

        [Browsable(true), Description("边框颜色")]
        [Category("Appearance")]
        public Color BorderColor
        {
            set { _borderColor = value; }
            get { return _borderColor; }
        }

        [Browsable(true), DefaultValue(2.0), Description("边框粗细")]
        [Category("Appearance")]
        public float BorderThickness
        {
            get { return _borderThickNess; }
            set { _borderThickNess = value; }
        }

        public InfoIcon()
        {
            BorderColor = Color.FromArgb(50, 113, 244);
            BorderThickness = 2;
            InitializeComponent();
        }

        protected override void OnPaint(PaintEventArgs pe)
        {
            base.OnPaint(pe);
            var graphics = pe.Graphics;
            graphics.SmoothingMode = SmoothingMode.AntiAlias;

            Pen pen = new Pen(BorderColor, BorderThickness);
            graphics.DrawEllipse(pen, BorderThickness / 2, BorderThickness / 2, Width - BorderThickness - 1, Height - BorderThickness - 1);

            Brush brush = new LinearGradientBrush(new PointF(0,Height / 2),new PointF(Width, Height / 2),Color.FromArgb(37, 108, 252),Color.FromArgb(54,162,249));
            graphics.FillEllipse(brush, BorderThickness / 2, BorderThickness / 2, Width - BorderThickness - 1, Height - BorderThickness - 1);

            pen = new Pen(Color.White, 2);
            float mul = Math.Min(((float)Width / 72),(float)Height / 72);

            graphics.FillEllipse(new SolidBrush(Color.White), (((float)Width) / 2) - 1*mul , 10 * mul, 8 * mul, 10 * mul);
            PointF[] pointFs = new PointF[10];
            pointFs[0] = new PointF((float)Width / 2 - 8 * mul, (10 + 8 + 16) * mul);
            pointFs[1] = new PointF((float)Width / 2 + 1 * mul, (10 + 8 + 8) * mul);  
            pointFs[2] = new PointF((float)Width / 2 + 4 * mul, (10 + 8 + 14) * mul); 
            pointFs[3] = new PointF((float)Width / 2 + 1 * mul, (10 + 8 + 32) * mul);
            pointFs[4] = new PointF((float)Width / 2 + 6 * mul, (10 + 8 + 28) * mul); //
            pointFs[5] = new PointF((float)Width / 2 + 8 * mul, (10 + 8 + 32) * mul);
            pointFs[6] = new PointF((float)Width / 2 - 1 * mul, (10 + 8 + 40) * mul); 
            pointFs[7] = new PointF((float)Width / 2 - 5 * mul, (10 + 8 + 34) * mul);
            pointFs[8] = new PointF((float)Width / 2 - 1 * mul, (10 + 8 + 16) * mul);
            pointFs[9] = new PointF((float)Width / 2 - 6 * mul, (10 + 8 + 20) * mul);
            graphics.FillClosedCurve(new SolidBrush(Color.White), pointFs);
        }
    }
}
